// wxWidgets "Hello World" Program

// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#include <wx/display.h>
#include "portaudio.h"

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "Win_Main.h"

#ifdef WIN32

#include <windows.h>

#if PA_USE_ASIO
#include "pa_asio.h"
#endif

#endif

MyFrame::MyFrame()
    : wxFrame(NULL, wxID_ANY, "Hello World"),m_mgr(this)
{
    wxMenu *menuFile = new wxMenu;
    menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
                     "Help string shown in status bar for this menu item");
    menuFile->AppendSeparator();
    menuFile->Append(wxID_EXIT);

    wxMenu *menuSetting = new wxMenu;
    menuSetting->Append(mW_ID_SETTING, "&Setting...\tCtrl-S",
                     "Help string shown in status bar for this menu item");

    wxMenu *menuHelp = new wxMenu;
    menuHelp->Append(wxID_ABOUT);

    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append(menuFile, "&File");
    menuBar->Append(menuSetting, "&Setting");
    menuBar->Append(menuHelp, "&Help");

    SetMenuBar( menuBar );

    CreateStatusBar();
    SetStatusText("Welcome to wxWidgets!");

    Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
    Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
    Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
    Bind(wxEVT_MENU, &MyFrame::OnSetting, this, mW_ID_SETTING);

    // Win_AudioWrite *w_audiowrite = new Win_AudioWrite(this,wxID_ANY,"Audio Write");
    // w_audiowrite->Show(true);

    PaError err = Pa_Initialize();
    if( err != paNoError )
    {
        wxLogWarning( "ERROR: Pa_Initialize returned 0x%x\n", err );
    }
}

void MyFrame::OnExit(wxCommandEvent& event)
{
    Pa_Terminate();
    Close(true);
}

void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxMessageBox("This is a wxWidgets Hello World example",
                 "About Hello World", wxOK | wxICON_INFORMATION);
}

void MyFrame::OnHello(wxCommandEvent& event)
{
    wxLogMessage("Hello world from wxWidgets!");
}

void MyFrame::OnSetting(wxCommandEvent& event)
{
    Win_Setting dlg_setting(this,wxID_ANY,"System Setting");
    dlg_setting.CenterOnParent();
    dlg_setting.ShowModal();
}